/*
 * QCalLoginWidget.cpp
 *
 *  Created on: Aug 30, 2010
 *      Author: deroy2
 */
#include <QStackedWidget>
#include <QSettings>
#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include "QCalLoginWidget.h"

QCalLoginWidget::QCalLoginWidget(QStackedWidget* stackedWid, QWidget *parent)
//: QWidget(stackedWidget,parent)
	{
	//createMenus();
	stackedWidget=stackedWid;
	QSettings setting("Nokia", "QTnetworkGUI");
	
	pWidget = new QWidget();
	
	name=new QLineEdit("abc@gmail.com");
	pass=new QLineEdit("password");
		//pass->setEchoMode(QLineEdit::Password);

	QPushButton* dnldButton = new QPushButton("&Login", this);
	QPushButton* nxtButton = new QPushButton("&Next Page", this);
	QObject::connect(dnldButton, SIGNAL(clicked()),
		                  this, SLOT(login()));
	QObject::connect(nxtButton, SIGNAL(clicked()),
			                  this, SLOT(nxtPage()));
	
	QVBoxLayout* layout = new QVBoxLayout();
	layout->addWidget(name);
	layout->addWidget(pass);
	layout->addWidget(dnldButton);
	layout->addWidget(nxtButton);
	this->setLayout(layout);
	//pWidget->showMaximized();
	
//	stackedWidget->addWidget(pWidget);
//	pWidget->show();
	
	authRetr = NULL; 
	evntRetr = NULL;
	}

QCalLoginWidget::~QCalLoginWidget()
	{
	//delete menuBar;
	if(authRetr)
	delete authRetr;
	}


//void QLoginWidget::createMenus()
//    {
//    
//    }

//QMenuBar* QLoginWidget::MenuBar() const
//    {
//    return menuBar;
//    }


void QCalLoginWidget::login()
	{
	

	QString url="https://www.google.com/accounts/ClientLogin";	
	QString name_fld=name->text();
	QString pass_fld=pass->text();
//	setting.setValue("Name",name_fld);
//	setting.setValue("Pass",pass_fld);
	authRetr= new QCalAuthRetriever;
	authRetr->load(url,name_fld,pass_fld);
	QObject::connect(authRetr, SIGNAL(downloadCompleted()),this, SLOT(ActivateCalender()));
	
//	upldr = new uploader;
//	upldr->load(url);
	}
void QCalLoginWidget::ActivateCalender()
	{
	
	stackedWidget->removeWidget(this);
	stackedWidget->setCurrentIndex(0);
	stackedWidget->show();
	emit logincomplete();
	}

void QCalLoginWidget::eventlistview(QDate date)
	{
//	QMyWidget2* newWidget = new QMyWidget2(stackedWidget,date);
//	stackedWidget->removeWidget(pWidget);
//	activateNewWidget(newWidget);
//	stackedWidget->addWidget(newWidget);
//	newWidget->show();
	}

